<?php 
session_start();
include "../_init_.php";
include(constant('PATH_INCLUDE').'/class.uploadhelper.php');

$action= isset($_REQUEST["action"])?$_REQUEST["action"]:'';
switch($action)
{
	case 'save':
			//delete images
	$sn_list = $_REQUEST['imageaddelete'];
	if($sn_list)
	{
		foreach($sn_list as $sn)
		{
		
			$imgPath = constant('SITE_WEB_DISK_DIR').Util::getGlobalValue('INDEX_IMAGE_PATH_AD_'.$sn);
			if(file_exists($img_path))
					@unlink($img_path);
					
        	Util::deleteGlobalValue('INDEX_IMAGE_PATH_'.$sn);
       	}
	}
	
	//insert or update image
	for($i=0;$i<constant('MAX_INDEX_AD_NUMBER');$i++)
	{
		
		Util::setGlobalValue('INDEX_AD_LINK_'.$i,$_REQUEST['INDEX_AD_LINK_'.$i]);
		try
		{
		$uploadDir = '/upload/';
		$path = UploadHelper::uploadImage('index_ad_image'.$i,$uploadDir);
		
		Util::setGlobalValue('INDEX_IMAGE_PATH_AD_'.$i,$path);
		}catch(Exception $ex)
		{
		}
	}
	break;
}



?>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>網站管理系統</title>


<LINK REL="stylesheet" HREF="css/style.css" TYPE="text/css">
<LINK REL="stylesheet" HREF="css/main.css" TYPE="text/css">
<script src="js/FancyZoom.js" language="JavaScript" type="text/javascript"></script>
<script src="js/FancyZoomHTML.js" language="JavaScript" type="text/javascript"></script>
<script src="../js/jquery-ui-1.7.3.custom/js/jquery-1.3.2.min.js" language="javascript"></script>
<body onLoad="setupZoom();">

<table width="100%" border="0" class="table2">
  <tr>
    <td>首頁管理 - 首頁廣告</td>
  </tr>
</table>
<?php if($error_message):?>
<div class="error_message"><?php echo $error_message;?></div>
<?php endif;?>
<?php if($sucess_message):?>
<div class="success_message"><?php echo $sucess_message;?></div>
<?php endif;?>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
     <tr>
     <td valign="top">
      <table width="100%" border="0" cellpadding="2" cellspacing="1" class="table_southidc">
        <tr> 
          <td  height="20" class="back_southidc"> <div align="center"><strong>首頁廣告管理</strong></div></td>
        </tr>
        <tr  class="tr_southidc">          
            <td bgcolor="#B0DAFF">
              <form method="post" enctype="multipart/form-data">
              <input type="hidden" name="action" value="save"/>
              <table width="100%" border="0"  cellpadding="10" cellspacing="2" bordercolor="#0000FF">
                <?php
                for($i=0;$i<constant('MAX_INDEX_AD_NUMBER');$i++)
				{
					$imgPath = Util::getGlobalValue('INDEX_IMAGE_PATH_AD_'.$i);
				?>
				<tr>
					 <td width="13%" height="22"> <div align="right">廣告圖片<?php echo $i+1;?>鏈接：</div></td>
					 <td bgcolor="#FFFFFF"><input type="text" name="INDEX_AD_LINK_<?php echo $i;?>" value="<?php echo Util::getGlobalValue('INDEX_AD_LINK_'.$i);?>"/></td>
				</tr>
	            <tr> 
                  <td width="13%" height="22"> <div align="right">廣告圖片<?php echo $i+1;?>：</div></td>
                  <td width="87%" bgcolor="#FFFFFF"><input name="index_ad_image<?php echo $i;?>" type="file"  size="15" maxlength="20">
                  <?php if($imgPath):?>
                  <image src="<?php echo constant('SITE_URL_PATH').$imgPath;?>" width="40" height="40"/><input type="checkbox" name="imageaddelete[]" value="<?php echo $i;?>"/>刪除
                  <?php endif;?>
                  &nbsp;最佳寬：288px.
                  </td>
                </tr>			
				<?php
				}
                ?>
              <tr>
              		<td colspan="2" align="center"><input type="submit" value="確認送出"/></td>
              </tr>
         	 </table>
         	 </form>
           </td>         
        </tr>
      </table>
    </td>
  </tr>
</table>
<?php  include("foot.php");?>